﻿@{
	Layout = "~/Views/Shared/_Layout.cshtml";
}

@using Hangerd.Utility;

@model Hangerd.Mvc.ViewModels.PagedListModel<dPet.Application.DataObjects.InventoryLORecordDto>

<div class="page-header">
	<h3>报损报溢记录</h3>
</div>

<div class="panel panel-default">
	<div class="panel-heading">
		@using (Html.BeginForm("InventoryLORecords", "Inventory", FormMethod.Get, new { @class = "form-inline", onsubmit = "return check_search_form()" }))
		{
			<div class="input-group">
				<span class="input-group-addon">商品条码</span>
				<input type="text" id="txt_product_barcode" name="ProductBarcode" class="form-control input-sm" value="@ViewBag.QueryDto.ProductBarcode" placeholder="点击此处进行扫码" onfocus="showScanBarcodePanel()" />
				<span class="input-group-btn">
					<button id="btn_search" class="btn btn-info btn-sm" type="submit"><span class="glyphicon glyphicon-search"></span> 查 询</button>
				</span>
			</div>
			
			<a href="@Url.Action("InventoryLORecords", "Inventory")" class="pull-right">清空筛选条件</a>
		}
	</div>
	<table class="table table-striped text-center">
		<thead>
			<tr>
				<th class="text-center">商品条码</th>
				<th class="text-center">商品名称</th>
				<th class="text-center">库存编号</th>
				<th class="text-center">类型</th>
				<th class="text-center">数量</th>
				<th class="text-center">操作人</th>
				<th class="text-center">操作时间</th>
			</tr>
		</thead>
		<tbody>
			@foreach (var record in Model.List)
			{
				<tr>
					<td>@record.ProductBarcode</td>
					<td>@record.ProductName</td>
					<td>@record.InventoryNumber</td>
					<td>@CommonTools.GetEnumDescription(record.LOType)</td>
					<td>@record.Quantity</td>
					<td>@record.Operator</td>
					<td>@record.LastModified.ToString("yyyy-MM-dd HH:mm:ss")</td>
				</tr>
			}
		</tbody>
	</table>
</div>

@HtmlUtil.BootstrapPager(Model.PageIndex, Model.PageSize, Model.TotalNumber,
	p => Url.Action("InventoryLORecords", "Inventory", new
	{
		ProductBarcode = ViewBag.QueryDto.ProductBarcode,
		pageIndex = p
	}))

<div class="modal fade" id="scan_Modal" tabindex="-1" role="dialog" aria-hidden="true">
	<br /><br /><br /><br />
	<div class="modal-dialog modal-sm">
		<div class="modal-content">
			<form onsubmit="fillProductBarcode()">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">读取条码</h4>
				</div>
				<div class="modal-body">
					<input id="txt_scaned_barcode" type="text" class="form-control" placeholder="读取条码" ng-model="scanedBarcode" />
				</div>
			</form>
		</div>
	</div>
</div>

@section scripts {
	<script type="text/javascript">
		$(document).ready(function () {
			set_left_nav('#ln_InventoryLORecords');
		});

		function showScanBarcodePanel() {
			$('#scan_Modal').modal('show');
		}

		$('#scan_Modal').on('shown.bs.modal', function (e) {
			$("#txt_scaned_barcode").val('');
			$('#txt_scaned_barcode').focus();
		});

		function fillProductBarcode() {
			var scanedBarcode = $.trim($("#txt_scaned_barcode").val());

			if (scanedBarcode != '') {
				$("#txt_product_barcode").val(scanedBarcode);
				$('#scan_Modal').modal('hide');
			}
		}

		function check_search_form() {
			if ($.trim($("#txt_product_barcode").val()) == '') {
				alert("请扫描商品条码");
				return false;
			}

			return true;
		}
	</script>
}